package com.jy.rhin.support.polymorphism.convertor;

import cn.org.chiss.rhin._2015.base.*;
import cn.org.chiss.rhin._2015.base.document.*;
import cn.org.chiss.rhin._2015.base.object.ObjectStatus;
import cn.org.chiss.rhin._2015.base.object.ObjectStatusPrimitive;
import cn.org.chiss.rhin._2015.document.management.DocumentStoredQueryResponse;
import com.jy.framework.base.utils.Converter;
import com.jy.rhin.sdk.dto.document.DocumentResultDto;
import com.jy.rhin.sdk.dto.document.DocumentSubmissionSetDto;
import com.jy.rhin.sdk.dto.document.query.FindSubmissionSetsDto;
import org.springframework.stereotype.Service;

import java.lang.String;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author dhl
 * @date 2022/6/21
 * @Description
 */
@Service("findSubmissionSets")
public class DocumentQueryHandler4FindSubmissionSets extends AbstractDocumentQueryHandler<FindSubmissionSetsDto, DocumentSubmissionSetDto> {

    @Override
    FindSubmissionSetsDto convertReq(Map<String, List<String>> dtoValueMap) {
        FindSubmissionSetsDto dto = new FindSubmissionSetsDto();
        dto.setId(QueryValueUtils.getStringValue("$SubmissionSetPatientId", dtoValueMap));
        dto.setSourceIdList(QueryValueUtils.getListValue("$SubmissionSetSourceId", dtoValueMap));
        dto.setSubmissionTimeStart(QueryValueUtils.getDateValue("$SubmissionSetSubmissionTimeFrom", dtoValueMap));
        dto.setSubmissionTimeEnd(QueryValueUtils.getDateValue("$SubmissionSetSubmissionTimeTo", dtoValueMap));
        dto.setContentTypeCodeList(QueryValueUtils.getListValue("$SubmissionSetContentType", dtoValueMap));
        return dto;
    }

    @Override
    DocumentResultDto<DocumentSubmissionSetDto> query(FindSubmissionSetsDto dto) {
        return documentSubmissionQueryHandler.findSubmissionSets(dto);
    }

    @Override
    DocumentStoredQueryResponse convertResp(List<DocumentSubmissionSetDto> resultList, List<String> jsonTextList) {
        DocumentStoredQueryResponse documentStoredQueryResponse = submissionSetConvert(jsonTextList);
        List<Folder> folder = new ArrayList<>();
        Folder folder1 = new Folder();
        folder1.setStatusCode(new ObjectStatus().setValue(ObjectStatusPrimitive.NEW));
        folder1.setUniqueId(new OID().setValue("102"));
        folder1.setLastUpdateTime(new DateTime().setValue("20230803144111"));
        Identifier identifier = new Identifier();
        identifier.setSystem(new URI().setValue("321321"));
        identifier.setValue(new ID().setValue("321321"));
        folder1.setPatientId(identifier);
        folder.add(folder1);
        documentStoredQueryResponse.setFolder(folder);

        /*List<Association> associations = new ArrayList<>();
        Association association = new Association();
        association.setTypeCode(new AssociationType().setValue("APND"));
        AssociationObject associationObject = new AssociationObject().setId(new URI().setValue("1"));
        associationObject.setStatus(new AssociationStatus().setValue(AssociationStatusPrimitive.REFERENCE));
        association.setSourceObject(associationObject);
        AssociationObject targat = new AssociationObject().setId(new URI().setValue("1"));
        targat.setStatus(new AssociationStatus().setValue(AssociationStatusPrimitive.REFERENCE));
        association.setTargetObject(targat);
        associations.add(association);
        documentStoredQueryResponse.setAssociation(associations);*/
        return documentStoredQueryResponse;
    }
}
